﻿using Architecture.CrossCutting.Common.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;

namespace Architecture.CrossCutting.Web.WCF
{
    public class WcfClientLog : BaseLog
    {

        public enum PipelineStep
        {
            BeforeCall = 0,
            AfterCall = 1,
            BeforeSendRequest = 2,
            AfterReceiveReply = 3
        };

        public PipelineStep Step { get; set; }

        public String OperationName { get; set; }

        public String Action { get; set; }

        public DateTime PipeLineStarted { get; set; }

        public Int64 PipeLineDuration { get; set; }

        public Int64 SerializationDuration { get; set; }

        public DateTime PipeLineEnded { get; set; }

        public DateTime RequestSended { get; set; }

        public Int64 RequestLength { get; set; }

        public Int64 RequestLogDuration { get; set; }

        public DateTime? ResponseReceived { get; set; }

        public Int64 ResponseLength { get; set; }

        public Int64 TransportDuration { get; set; }

        public Boolean IsFault { get; set; }

        public WcfClientLog() : base() { }


        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("CorrelationId : {0}", this.CorrelationId);
            sb.AppendLine();

            sb.AppendFormat("Step : {0}", this.Step);
            sb.AppendLine();

            sb.AppendFormat("Action : {0}", this.Action);
            sb.AppendLine();

            sb.AppendFormat("OperationName : {0}", this.OperationName);
            sb.AppendLine();

            sb.AppendFormat("PipeLineStarted : {0}", this.PipeLineStarted);
            sb.AppendLine();

            sb.AppendFormat("PipeLineEnded : {0}", this.PipeLineEnded);
            sb.AppendLine();

            sb.AppendFormat("PipeLineDuration : {0}", this.PipeLineDuration);
            sb.AppendLine();

            sb.AppendFormat("RequestSended : {0}", this.RequestSended);
            sb.AppendLine();

            sb.AppendFormat("RequestLength : {0}", this.RequestLength);
            sb.AppendLine();

            sb.AppendFormat("RequestLogDuration : {0}", this.RequestLogDuration);
            sb.AppendLine();

            sb.AppendFormat("ResponseReceived  : {0}", this.ResponseReceived);
            sb.AppendLine();

            sb.AppendFormat("ResponseLength  : {0}", this.ResponseLength);
            sb.AppendLine();

            sb.AppendFormat("TransportDuration  : {0}", this.TransportDuration);
            sb.AppendLine();

            sb.AppendFormat("IsFault  : {0}", this.IsFault);
            sb.AppendLine();

            return sb.ToString();
        }

    }
}
